//
//  BaseCollectionViewCell.m
//  GiftSay
//
//  Created by QQn1993 on 16/1/8.
//  Copyright © 2016年 liyinkai. All rights reserved.
//

#import "BaseCollectionViewCell.h"

#import <YYKit/UIImageView+YYWebImage.h>

@interface BaseCollectionViewCell ()

@property (nonatomic,strong) UIImageView *bagImg;
@property (nonatomic,strong) UIImageView *likeimg;
@property (nonatomic,strong) UILabel *title;
@property (nonatomic,strong) UILabel *price;
@property (nonatomic,strong) UILabel *like;

@end

@implementation BaseCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    
    if (self) {
        
        self.bagImg = [[UIImageView alloc] init];
        self.bagImg.backgroundColor = [UIColor lightGrayColor];
        [self.contentView addSubview:self.bagImg];
        
        self.title = [[UILabel alloc] init];
        self.title.textAlignment = NSTextAlignmentCenter;
        [self.contentView addSubview:self.title];
        
        self.price = [[UILabel alloc] init];
        self.price.textColor = [UIColor redColor];
        self.price.font = [UIFont systemFontOfSize:14 * SCREEN_WIDTH];
        [self.contentView addSubview:self.price];
        
        self.like = [[UILabel alloc] init];
        self.like.textColor = [UIColor grayColor];
        self.like.font = [UIFont systemFontOfSize:13 * SCREEN_WIDTH];
        self.like.textAlignment = NSTextAlignmentRight;
        
        [self.contentView addSubview:self.like];
        
    }
    return self;
}


- (void)setItem:(Items *)item
{
    if (_item != item) {
        _item = item;
    }
    
    [self.bagImg setImageWithURL:[NSURL URLWithString:item.cover_icon] options:YYWebImageOptionProgressiveBlur];
    
    self.title.text = item.title;
    self.price.text = [NSString stringWithFormat:@"￥%@",item.price];
    
    self.like.text = [NSString stringWithFormat:@"♡%@",item.like];
    if ([[NSUserDefaults standardUserDefaults] boolForKey:@"NightMode"] == YES){
        self.backgroundColor = kNightModeColor;
        self.title.textColor = [UIColor whiteColor];
    }
    else{
        self.backgroundColor = [UIColor whiteColor];
        self.title.textColor = [UIColor blackColor];
    }
}

- (void)layoutSubviews
{
    [super layoutSubviews];
    
    self.bagImg.frame = CGRectMake(0, 0, self.contentView.bounds.size.width, self.contentView.bounds.size.width);
    
    CGFloat h = self.contentView.bounds.size.height - self.contentView.bounds.size.width;
    
    self.title.frame = CGRectMake(0, self.contentView.bounds.size.width, self.contentView.bounds.size.width, h / 3 * 2);
    
    self.price.frame = CGRectMake(0, self.contentView.bounds.size.width + h / 3 * 2, self.contentView.bounds.size.width / 2, h / 3);
    
    self.like.frame = CGRectMake(self.contentView.bounds.size.width / 2, self.price.frame.origin.y, self.contentView.bounds.size.width / 2, h / 3);
    
}

@end
